﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Transactions {
    import Engine.Transactions.*;
    import Classes.*;
    import Display.*;

    public class TBuyItem extends Transaction {

        private var m_itemName:String;
        private var m_itemAmount:int;
        private var m_success:Boolean;
        private var m_unlockItemName:String;

        public function TBuyItem(_arg1:String, _arg2:int, _arg3:String=null){
            var _local4:Item;
            super();
            this.m_itemName = _arg1;
            this.m_itemAmount = _arg2;
            this.m_unlockItemName = _arg3;
            this.m_success = Global.player.inventory.addItems(this.m_itemName, this.m_itemAmount);
            if (this.m_success){
                _local4 = Global.gameSettings.getItemByName(this.m_itemName);
                if (_local4.cost > 0){
                    Global.player.gold = (Global.player.gold - (_local4.cost * this.m_itemAmount));
                } else {
                    if (_local4.cash > 0){
                        Global.player.cash = (Global.player.cash - (_local4.cash * this.m_itemAmount));
                    } else {
                        GlobalEngine.msg((this.m_itemName + " costs nothing, make sure this is intentional behavior."));
                    };
                };
            } else {
                UI.displayMessage(ZLoc.t("Dialogs", "InventoryFull"));
            };
        }
        override public function perform():void{
            if (this.m_success){
                signedCall("UserService.buyConsumable", this.m_itemName, this.m_itemAmount, this.m_unlockItemName);
            };
        }

    }
}//package Transactions 
